﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using Douban.Modules.Conversation.Models;
using System.Reflection;
using Douban.Api;

namespace Douban.Modules.Conversation.Controls
{
    public class MessageListItemSelector : DataTemplateSelector
    {
        public DataTemplate SentMessageTemplate { get; set; }

        public DataTemplate ReceivedMessageTemplate { get; set; }

        public string PropertyToEvaluate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            MessageModel message = (MessageModel)item;

            Type type = message.GetType();
            PropertyInfo property = type.GetProperty(PropertyToEvaluate);

            DoubanService doubanService = new DoubanService();
            doubanService.Run();
            string PropertyValue = doubanService.UserService.CurrentUser.Id;

            if (property.GetValue(message, null).ToString() == PropertyValue)
            {
                return SentMessageTemplate;
            }
            else
            {
                return ReceivedMessageTemplate;
            }
        }
    }
}
